import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";


type homeResult = {
  page: any;
  result: any
};


export type UserResult = {
  // success: boolean;
  // data: {
  //   /** 用户名 */
  //   username: string;
  //   /** 当前登陆用户的角色 */
  //   roles: Array<string>;
  //   /** `token` */
  //   accessToken: string;
  //   /** 用于调用刷新`accessToken`的接口时所需的`token` */
  //   refreshToken: string;
  //   /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
  //   expires: Date;
  // };
  page: any
  result: {
    id: string | number;
    token: string;
    username: string;
    name: string;
    qx: string | number;
  }
};

export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

/** 登录 */
export const getLogin = (data?: object) => {
  // return http.request<UserResult>("post", baseUrlApi("/api/backend/authregister/authlogin"), { data });
  return http.request<UserResult>("post", baseUrlApi('/manageuser/login'), { data });
};


// 管理员管理
/** 新增管理员管理 */
export const addUser = (data?: object) => {
  return http.request<homeResult>("post", baseUrlApi("/manageuser/insert"), { data });
};

/** 后台管理用户列表查询 */
export const manageuser = (data?: object) => {
  return http.request<RefreshTokenResult>("get", baseUrlApi("/manageuser/all"), { data });
};


/** 删除管理员管理 */
export const userdelinfo = (userid?: string | number) => {
  return http.request<homeResult>("delete", baseUrlApi(`/manageuser/deleteById/${userid}`));
};


/** 修改管理员管理 */
export const manageuserupdate = (data?: object) => {
  return http.request<homeResult>("post", baseUrlApi("/manageuser/update"), { data });
};




/** 刷新token */
export const refreshTokenApi = (data?: object) => {
  return http.request<RefreshTokenResult>("get", baseUrlApi("/api/backend/authregister/qx"), { data });
};


// 用户管理
/** 新增用户 */
export const addclient = (data?: object) => {
  return http.request<homeResult>("post", baseUrlApi("/xuserController/insert"), { data });
};

/** 删除用户 */
export const deleteclient = (data?: object) => {
  return http.request<homeResult>("post", baseUrlApi("/fortest/delbyid"), { data });
};


/** 删除用户 */
export const deleteAll = (data?: object) => {
  return http.request<homeResult>("post", baseUrlApi("/fortest/delbyids"), { data });
};


// /** 删除用户 */
// export const deleteclient = (userid?: string | number) => {
//   return http.request<homeResult>("delete", baseUrlApi(`/fortest/delbyid/${userid}`));
// };


/** 修改用户 */
export const updateclient = (data?: object) => {
  return http.request<homeResult>("post", baseUrlApi("/fortest/update"), { data });
};


/** 列表查询 */
export const manageclient = (data?: object) => {
  return http.request<RefreshTokenResult>("post", baseUrlApi("/fortest/selbypage"), { data });
};

/** 根据厂商ID 查询所有人员 */
export const xuserControllerxuserController = (factoryId?: string) => {
  return http.request<RefreshTokenResult>("get", baseUrlApi(`/xuserController/selusers/${factoryId}`));
};













